﻿using System;

namespace YArchitech.MEP
{
	public class HYDuctSystem : HYSystem
	{
		public bool IsConfluence { get; set; }

		public HYDuctSpecifications MainRects { get; set; }

		public HYDuctSpecifications SideRects { get; set; }

		public HYDuctSpecifications Rounds { get; set; }

		public override bool Design(HYSystemOption op)
		{
			if (!base.Design(op))
			{
				return false;
			}
			HYDuctSystemOption hyductSystemOption = op as HYDuctSystemOption;
			foreach (HYTube hytube in base.Tubes)
			{
				HYDuct hyduct = hytube as HYDuct;
				double velocity = hyductSystemOption.GetVelocity(hytube.Place);
				if (hyduct.Size.Shape == HYTubeShape.Round)
				{
					hyduct.Size = this.Rounds.SelectSectionByVelocity(hyduct.Flow, velocity).Size;
				}
				else if (hytube.Place == HYBranchPlace.Main)
				{
					hyduct.Size = this.MainRects.SelectSectionByVelocity(hyduct.Flow, velocity).Size;
				}
				else
				{
					hyduct.Size = this.SideRects.SelectSectionByVelocity(hyduct.Flow, velocity).Size;
				}
			}
			return this.Check(hyductSystemOption);
		}

		public override bool Check(HYSystemOption option)
		{
			return base.Check(option);
		}
	}
}
